package cn.lyn4ever.cataccount.service.impl;

import cn.lyn4ever.cataccount.entity.IconUserPath;
import cn.lyn4ever.cataccount.mapper.IconUserPathMapper;
import cn.lyn4ever.cataccount.service.IconUserPathService;
import cn.lyn4ever.common.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IconUserPathServiceImpl implements IconUserPathService {
    @Resource
    private IconUserPathMapper iconUserPathMapper;
    private Map<String, Object> map;


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public IconUserPath queryById(Integer id) {
        return null;
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<IconUserPath> queryAllByLimit(int offset, int limit) {
        return null;
    }

    /**
     * 新增数据
     *
     * @param iconUserPath 实例对象
     * @return 实例对象
     */
    @Override
    public R insert(IconUserPath iconUserPath) {
        int line = iconUserPathMapper.insert(iconUserPath);
        if (line > 0) return R.sucess("添加成功");
        return R.fail("添加失败");
    }

    /**
     * 修改数据
     *
     * @param iconUserPath 实例对象
     * @return 实例对象
     */
    @Override
    public IconUserPath update(IconUserPath iconUserPath) {
        return null;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return false;
    }

    /**
     * 查询用户所有图标
     *
     * @param path
     * @return
     */
    @Override
    public R getAllIcon(IconUserPath path) {
        Map<String, Object> map = new HashMap<>();

        //如果有type就是指定要查哪个类型的，没有就查支出和输入
        if(null!=path.getType() && !"".equals(path.getType().trim())){
            List<IconUserPath> list1 = iconUserPathMapper.getAll(path);
            if (null != list1 && list1.size() > 0) {
                return R.sucess("查询成功", list1);
            }
        }

        path.setType("0");//支出
        List<IconUserPath> list = iconUserPathMapper.getAll(path);
        map.put("payIcons", list);

        path.setType("1");//收入
        list = iconUserPathMapper.getAll(path);
        map.put("incomeIcons", list);

        if (null != map && map.size() > 0) {
            return R.sucess("查询成功", map);
        }

        return R.fail();
    }
}
